package org.fdy.bgadmin.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fdy.bgadmin.service.OcrService;
import org.fdy.bgadmin.utils.OcrUtils;
import org.fdy.common.core.model.Result;
import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>描述：</p>
 *
 * @author fangdy
 * @create 2024-01-02 23:27
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OcrServiceImpl implements OcrService {
    @Override
    public Result<List<String>> fileToText(MultipartFile file) {
        byte[] bytes = new byte[0];
        try {
            bytes = file.getBytes();
        } catch (IOException e) {
            log.error("文件异常",e);
        }
        String s = Base64Utils.encodeToString(bytes);
        List<String> list = OcrUtils.base64ToArrs(s);
        return Result.ok(list);
    }
}
